package cn.yeyiu.sexyiu.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import cn.yeyiu.sexyiu.R;
import cn.yeyiu.sexyiu.listener.OnItemClickListener;
import cn.yeyiu.util.ExternalJSONFile;
import cn.yeyiu.util.MediaUtil;
import cn.yeyiu.util.bean.TimeVideoInfo;

import com.bumptech.glide.Glide;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Locale;

public class DateListAdapter extends RecyclerView.Adapter<DateListAdapter.ViewHolder> {
    private final Context mContext;
    public final List<TimeVideoInfo> dataList;
    private final SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
    private final LayoutInflater inflater;
    private OnItemClickListener onItemClickListener;

    public DateListAdapter(Context context, String type) {
        this.mContext = context;
        this.inflater = LayoutInflater.from(context);
        this.dataList = ExternalJSONFile.loadDatas(context, type);
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View inflate = this.inflater.inflate(R.layout.item_date_video, viewGroup, false);
        inflate.setOnClickListener(v -> {
            this.onItemClickListener.onItemClick(v);
        });
        inflate.setOnLongClickListener(v -> {
            this.onItemClickListener.onItemLongClick(v);
            return true;
        });
        return new ViewHolder(inflate);
    }

    public void onBindViewHolder(ViewHolder viewHolder, int i) {
        List<TimeVideoInfo> list = this.dataList;
        TimeVideoInfo timeVideoInfo = list.get((list.size() - 1) - i);
        MediaUtil.fixLocalVideoInfo(timeVideoInfo);

        viewHolder.title.setText(timeVideoInfo.title);
        viewHolder.time.setText(this.formatter.format(new Date(Long.parseLong(timeVideoInfo.time))));
        String category = timeVideoInfo.code +"-"+timeVideoInfo.type;
        viewHolder.category.setText(category);
        Glide.with(this.mContext)
                .load(timeVideoInfo.picSrc)
                .placeholder(R.drawable.jpg_home_header)
                .into(viewHolder.image);
    }

    @Override // androidx.recyclerview.widget.RecyclerView.Adapter
    public int getItemCount() {
        List<TimeVideoInfo> list = this.dataList;
        if (list == null) {
            return 0;
        }
        return list.size();
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener2) {
        this.onItemClickListener = onItemClickListener2;
    }

    /* access modifiers changed from: package-private */
    public static class ViewHolder extends RecyclerView.ViewHolder {
        TextView category;
        ImageView image;
        TextView time;
        TextView title;

        public ViewHolder(View view) {
            super(view);
            this.image = (ImageView) view.findViewById(R.id.data_pic_img);
            this.title = (TextView) view.findViewById(R.id.data_title_tv);
            this.time = (TextView) view.findViewById(R.id.time_tv);
            this.category = (TextView) view.findViewById(R.id.category_tv);
        }
    }
}
